package com.itheima.health.service.impl;

import com.itheima.health.common.MessageConst;
import com.itheima.health.dao.OrderDao;
import com.itheima.health.dao.OrderSettingDao;
import com.itheima.health.exception.BusinessRuntimeException;
import com.itheima.health.pojo.*;
import com.itheima.health.service.OrderService;
import com.itheima.health.vo.OrderSubmitParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 预约ServiceImpl
 */
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderSettingDao orderSettingDao;
    @Autowired
    private OrderDao orderDao;


    /**
     * 查询提交预约日期是否重复
     * @param userId 刚提交预约单用户的id
     * @param orderDate 预约的时间
     * @param setMealId 预约的套餐
     * @return 返回查询结果
     */
    @Override
    public Order selectOrdeDate(int userId, Date orderDate, Integer setMealId) {

        return orderDao.selectOrdeDate(userId, orderDate, setMealId);
    }

    /**
     * 添加预约表单到数据库中
     * @param orderSubmitParam 用户提交的预约表单
     * @return 返回id
     */
    @Override
    public int add(OrderSubmitParam orderSubmitParam, int userId) {
        log.info("userId:"+userId);
        orderDao.add(orderSubmitParam, userId);
        log.info("add:"+orderSubmitParam.getId());
        return orderSubmitParam.getId();
    }

    /**
     * 查询刚添加进数据库的预约表单
     * @param id 刚添加进数据库的预约表单
     * @return 返回表单
     */
    @Override
    public Order seleceByIdupdata(int id) {

        Order order = orderDao.seleceByIdupdata(id);
        log.info("OrderServiceImpl的seleceById"+order);
        return orderDao.seleceByIdupdata(id);
    }

    @Override
    public String selectByIdUserName(int id) {
        return orderDao.selectByIdUserName(id);
    }

    @Override
    public String selectByIdGroupName(int id) {
        return orderDao.selectByIdGroupName(id);
    }
    @Override
    public OrderInfo findId(Integer id) {

        return  orderDao.selectById(id);
    }
}
